Skip to main content

Pointer: SUPER

The SUPER pointer is a special variable which is used for object-oriented programming.

SUPER is the pointer of a function block to the base function block instance from which the function block was generated. The SUPER pointer also allows access to the implementation of the methods of the base function block (base class). A SUPER pointer is automatically available for each function block. You can use SUPER only in methods and in the associated function block implementations.

Dereferencing of the pointer: SUPER^

Using the SUPER pointer: With the SUPER keyword, you call a method which is valid in the instance of the basic class or parent class.

Example 98. Example

ST

SUPER^.METH_DoIt();

FBD/CFC/LD

_cds_img_pointer_super_fbd.png


Example 99. Example

Use of SUPER and THIS pointers

FUNCTION_BLOCK FB_Base
VAR_OUTPUT
        iCnt : INT;
END_VAR

METHOD METH_DoIt : BOOL
iCnt := -1;

METHOD METH_DoAlso : BOOL
METH_DoAlso := TRUE;

FUNCTION_BLOCK FB_1 EXTENDS FB_Base
VAR_OUTPUT
        iBase : INT;
END_VAR

THIS^.METH_DoIt();  //Call of the methods of FB_1
THIS^.METH_DoAlso();

SUPER^.METH_DoIt();   //Call of the methods of FB_Base
SUPER^.METH_DoAlso();
iBase := SUPER^.iCnt;

METHOD METH_DoIt : BOOL
iCnt := 1111;
METH_DoIt := TRUE;

PROGRAM PLC_PRG
VAR
    myBase : FB_Base;
    myFB_1 : FB_1;
    iTHIS : INT;
    iBase : INT;
END_VAR
myBase();
iBase := myBase.iCnt;
myFB_1();
iTHIS := myFB_1.iCnt;


Tip

THIS is not yet implemented for the instruction list (IL).